import React from 'react';
import AppBar from 'material-ui/AppBar';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import ActionsNoLogin from './ActionsNoLogin';

class AppBarExampleIconButton extends React.Component {
    constructor(props) {
        super(props)

        this.state = {
            username: null,
            // username: 'kobako',
        }

        this.loginSuccess = this.loginSuccess.bind(this)
    }

    loginSuccess(userInfo) {
        console.info('App :: loginSuccess() : ' + JSON.stringify(userInfo))
        this.user = userInfo
        this.setState({
            username: userInfo.name
        })

        window.myApp = this
    }

    render() {
        return (
            <MuiThemeProvider>
                <div>
                    <AppBar
                        title={<span style={{cursor: 'pointer'}}>调查问卷中心</span>}
                        iconElementRight={
                            this.state.username ? <div style={{color: 'white'}}>欢迎,{this.state.username}</div>
                                : <ActionsNoLogin login={this.loginSuccess}/>
                        }
                    />

                </div>
            </MuiThemeProvider>
        )
    }
}

export default AppBarExampleIconButton;